package com.web.service;

import com.web.dao.NoticeMapper;
import com.web.VO.UnReadNoticeVO;
import com.web.entity.Notice;
import com.web.entity.UserInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class NoticeService {

    @Resource
    private NoticeMapper noticeMapper;

    /**
     * 插入通知消息
     * @param notice
     */
    public Integer insert(Notice notice) {
        Integer id = noticeMapper.insertSelective(notice);
        return id;
    }

    /**
     * 查询通知消息
     * @param type
     * @param userId
     * @return
     */
    public List<Notice> listNotice(Integer type, String userId) {
        return noticeMapper.listNotice(type, userId);
    }

    /**
     * 未读消息数
     * @param info
     * @return
     */
    public UnReadNoticeVO getUnReadNoticeNum(UserInfo info) {
        UnReadNoticeVO unReadNoticeVO = new UnReadNoticeVO();
        for (int i = 1; i < 8; i++) {
            Notice notice = new Notice();
            notice.setTarget(info.getUserId());
            notice.setType(i);
            int num = noticeMapper.unReadNum(notice);
            if (i == 1) {
                unReadNoticeVO.setOneNum(num);
            } else if (i == 2) {
                unReadNoticeVO.setTwoNum(num);
            } else if (i == 3) {
                unReadNoticeVO.setThreeNum(num);
            } else if (i == 4) {
                unReadNoticeVO.setFourNum(num);
            } else if (i == 5) {
                unReadNoticeVO.setFiveNum(num);
            } else if (i == 6) {
                unReadNoticeVO.setSixNum(num);
            } else if (i == 7) {
                unReadNoticeVO.setSevenNum(num);
            }
        }
        return unReadNoticeVO;
    }


    /**
     * 判断用户是否重复应聘
     * @param sender
     * @param contentId
     * @return
     */
    public Notice searchIsRepeatRecruit(String sender, Integer contentId) {
        return noticeMapper.searchIsRepeatRecruit(sender, contentId);
    }

    /**
     * 判断用户是否重复聘用
     * @param sender
     * @param contentId
     * @return
     */
    public Notice searchIsRepeatJobApply(String sender, Integer contentId) {
        return noticeMapper.searchIsRepeatJobApply(sender, contentId);
    }
}
